<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_left">
          <div>
            {{ i18n('kernel.setting.center') }}
          </div>
        </div>
      </div>

      <div class="admin_form_main">
        <el-tabs v-model="activeName" @tab-click="handleClick">
          <el-tab-pane
            v-for="(v, k) in configList"
            :label="v.name"
            :name="v.id"
            :key="k"
            :lazy="true">
            <el-card class="box-card" shadow="never">
              <template v-slot:header>
                <div class="clearfix">
                  {{ v.content }}
                </div>
              </template>
              <div class="text item color">
                <form-component :category_id="category_id"></form-component>
              </div>
            </el-card>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>

<script setup name="setting-form">
  import { useBase } from "@/hooks/base/useBase"
  import formComponent from '@/components/form/component'

  const { i18n } = useBase()

  const activeName = ref(1)
  const configList = ref([])
  const category_id = ref(1)

  const loadConfigList = () => {
    $http({
      url: $http.adornUrl('/config/category/select'),
      method: 'get',
      params: $http.adornParams(),
    }).then(({ data }) => {
      if (data && data.status === 200) {
        configList.value = data.data
        activeName.value = data.data[0].id || 0
        category_id.value = data.data[0].id || 0
      } else {
        $message.error(data.message)
      }
    })
  }

  const handleClick = (tab, event) => {
    category_id.value = tab.paneName || 0
  }

  onMounted(() => {
    loadConfigList()
  })
</script>
